<?php

/**
 * project actions.
 *
 * @package    vo-ser
 * @subpackage project
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class projectActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $r)
    {
        $this->project = $this->getProject($r);
    }
	
	public function executeDelete(sfWebRequest $r)
	{
		$p = $this->getProject($r);
		
		$user = $this->getUser()->getUserObject();
		
		if ($p->getOwner()->getId() == $user->getId())
		{
			$name = $p->getName();
			$p->delete();
			$this->getUser()->setFlash('flash', "Project $name deleted");
		}
		
		$this->redirect('@homepage');
	}
	
	private function getProject(sfWebRequest $r)
	{
		$projectName = SER::deSlugify($r->getParameter('pr_slug'));
		
		return Doctrine::getTable('Project')->findOneByName($projectName);
	}
}
